package com.scalar.chiptrack.operations.packingslip.actions;

import com.scalar.chiptrack.ChipTrackAction;
import com.scalar.chiptrack.commons.SessionKeys;
import com.scalar.chiptrack.users.User;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class VendorPackingSlipAction extends ChipTrackAction
{

	public ActionForward execute (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
	{
		HttpSession session = request.getSession();
		String action = request.getParameter("action");

        request.setAttribute ( "AUTO_CONFIRM_PACKING_SLIP" , request.getParameter ("autoConfirmPackingSlip") );

        User user = (User) session.getAttribute (SessionKeys.USER_KEY);

        if (user == null)
		{
            session.setAttribute ( SessionKeys.SOURCE_PAGE_KEY , "/extUserSearchPackingSlip.do" );
            return ( mapping.findForward( SessionKeys.ACTION_FORWARD_KEY_LOGIN ) );
        }
        if( "loadSalesOrder".equalsIgnoreCase( action ) )
		{
			return new GeneratePackingSlipAction().execute( mapping, form, request, response );
		}
		else if( "save".equalsIgnoreCase( action ) )
		{
			return new SavePackingSlipAction().execute( mapping, form, request, response );
		}

		return null;
	}
}
